package com.kjtpay.design_pattern.command;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

class Waiter {
    // 命令的集合
    private ArrayList<Command> orders = new ArrayList<Command>();
    // 日志
    private String log = "";

    // 下单
    public void setOrder(Command command) {
        if ("new" == command.name) {
            log += "服务员：新产品还没有推出，请点别的烧烤。\n";
        } else {
            orders.add(command);
            log += "增加订单：" + command.name + " === 时间："
                    + getCurrentTimeString() + "\n";
        }
    }

    // 取消订单
    public void cancelOrder(Command command) {
        if (orders.contains(command)) {
            orders.remove(command);
            log += "取消订单：" + command.name + " === 时间："
                    + getCurrentTimeString() + "\n";
        }
    }

    // 通知执行
    public void  notice() {
        for (Command command:
             orders) {
            log += command.executeCommand() + "\n";
        }
    }

    // 显示日志
    public String show() {
        return log;
    }

    // 重置
    public void reset() {
        orders.clear();
        log = "";
    }

    // 下单时间
    private String getCurrentTimeString() {
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年-MM月dd日-HH时mm分ss秒 E");
        return dateFormat.format(date);
    }
}
